package com.wuye.repository;

import com.wuye.model.option.UserOption;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;

import java.util.List;

/**
 * Created by jiawenlong on 2016/8/1.
 */
public interface UserOptionRepository extends PagingAndSortingRepository<UserOption, Long> {

    @Query(nativeQuery = true, value = "select * from UserOption  where " +
            "  name LIKE %:qv% or phone LIKE %:qv% " +
            "  order by id desc LIMIT :st, :ps")
    List<UserOption> queryOptions( @Param("qv") String qVal,
                             @Param("st") int start, @Param("ps") int pageSize);
    @Query(nativeQuery = true, value = "SELECT COUNT(DISTINCT id) from UserOption  where " +
            "  name LIKE %:qv% or phone LIKE %:qv% " )
    int queryOptionCount( @Param("qv") String qVal);
}
